package org.andy.work.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name="acct_role",catalog="work")
public class AcctRole {
	
	private String id;
	private String name;
	private Set<AcctUser> acctUsers = new HashSet<AcctUser>();
	private Set<AcctAuthority> accAuthorities = new HashSet<AcctAuthority>();
	public AcctRole() {
		super();
		// TODO Auto-generated constructor stub
	}
	public AcctRole(String id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	public AcctRole(String id, String name, Set<AcctUser> acctUsers,
			Set<AcctAuthority> accAuthorities) {
		super();
		this.id = id;
		this.name = name;
		this.acctUsers = acctUsers;
		this.accAuthorities = accAuthorities;
	}
	
	@Id
	@Column(name="id",unique=true,nullable=false,length=36)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}

	@Column(name="name",nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="acct_user_role",catalog="work",
		joinColumns={@JoinColumn(name="role_id",nullable=false,updatable=false)},
		inverseJoinColumns={@JoinColumn(name="user_id",nullable=false,updatable=false)})
	public Set<AcctUser> getAcctUsers() {
		return acctUsers;
	}
	public void setAcctUsers(Set<AcctUser> acctUsers) {
		this.acctUsers = acctUsers;
	}
	
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="acct_role_authority",catalog="work",
			joinColumns={@JoinColumn(name="role_id",nullable=false,updatable=false)},
			inverseJoinColumns={@JoinColumn(name="authority_id",nullable=false,updatable=false)})
	public Set<AcctAuthority> getAccAuthorities() {
		return accAuthorities;
	}
	
	public void setAccAuthorities(Set<AcctAuthority> accAuthorities) {
		this.accAuthorities = accAuthorities;
	}
	
	
	
}
